class Invoice:
    def __init__(self, customer_name, sale_date):
        self.customer_name = customer_name
        self.sale_date = sale_date
        self.items = []  # 用于存储购买的商品

    def add_item(self, item_name, quantity, unit_price):
        subtotal = quantity * unit_price
        self.items.append({
            'item_name': item_name,
            'quantity': quantity,
            'unit_price': unit_price,
            'subtotal': subtotal
        })

    def print_invoice(self):
        # 发票头部
        print("----------- 发票 -----------")
        print(f"顾客姓名: {self.customer_name}")
        print(f"销售日期: {self.sale_date}")
        print("---------------------------")

        # 发票主体
        print("商品清单:")
        print(f"{'商品名称':<15} {'数量':<10} {'单价':<10} {'小计':<10}")
        print("-" * 50)
        total_amount = 0
        for item in self.items:
            print(f"{item['item_name']:<15} {item['quantity']:<10} {item['unit_price']:<10} {item['subtotal']:<10}")
            total_amount += item['subtotal']

        # 发票尾部
        print("-" * 50)
        print(f"总金额: {total_amount:.2f}")
        print("---------------------------")


# 主程序
if __name__ == "__main__":
    customer_name = input("请输入顾客姓名: ")  # 输入顾客姓名
    sale_date = input("请输入销售日期 (格式: YYYY-MM-DD): ")  # 输入销售日期

    invoice = Invoice(customer_name, sale_date)  # 创建发票实例

    while True:
        item_name = input("请输入商品名称 (输入 'exit' 结束输入): ")
        if item_name.lower() == 'exit':
            break
        quantity = int(input("请输入购买数量: "))  # 输入购买数量
        unit_price = float(input("请输入单价: "))  # 输入单价

        invoice.add_item(item_name, quantity, unit_price)  # 添加商品

    # 打印发票
    invoice.print_invoice()
